function Ship()
{                    
    this.x = 250;
    this.y = 375;
    this.image = document.getElementById( 'ship' );
    this.gasShotPicture = document.getElementById( 'gasShot' ); 
    this.gasFire = document.getElementById( 'gasFire' );
    this.shot = document.getElementById( 'shotPlay' ); 
    this.speed = 15;
    this.shipWidth = 100;
    this.shipHeight = 65;                       
    this.life = 3;
    this.score = 0;
    this.numDestroyedAsteroids = 0;
    this.effectTime = 0;
    this.lazerGun = [];
    this.numLazer = 12;
    this.gasShotEffect = 'false';
    this.gasFireEffect = 0;
}

Ship.prototype.draw = function( context, all )
{     
    context.save();

    if ( this.x < 15 )
    {
        this.x = 15;
    }
    if ( this.x > all.width - this.shipWidth - 10 )
    {
        this.x = all.width - this.shipWidth - 10;
    }
    if ( this.y > all.height - this.shipHeight - 10 )
    {   
        this.y = all.height - this.shipHeight - 10;
    }                                                                
    if ( this.y < ( all.height / 2 ) )
    {
        this.y = all.height / 2;
    }
    context.translate( this.x, this.y );
    if ( this.gasShotEffect == 'true' )
    {
        context.drawImage( this.gasShotPicture, 0, -3, 15, 15 );
        context.drawImage( this.gasShotPicture, 84, -3, 15, 15 );
        this.gasShotEffect = 'false';
    } 
    context.drawImage( this.image, 0, 0, this.shipWidth, this.shipHeight );
    if ( this.gasFireEffect == 1 )
    {
        context.drawImage( this.gasFire, 20, 52, 17, 18 );        
        context.drawImage( this.gasFire, 62, 52, 17, 18 );
        this.gasFireEffect = 0;
    }
    else
    {
        this.gasFireEffect = 1;
    }
    context.restore();
};

function effectShipDied( time )
{
    var num = 0;
    var effectTime = 0;
    var redeliver = {effect: 'true', effectTime: time}    

    if ( redeliver.effectTime != 0 )
    {
        num = Math.floor( redeliver.effectTime );
        num = num % 2;
        redeliver.effectTime -= 0.25;
    }
    redeliver.effect = ( redeliver.effectTime == 0 || num == 0 ) ? 'false' : 'true'; 
    return redeliver;
}